class CategoryController < ApplicationController
  
  def list_with_initial
    @current_initial = params[:id]    
    @categories_with_initial = Category.with_prefix(@current_initial)
    @page_title = "#{@current_initial} Categories"
    @is_show_category_initials = true
  end
  
  def show
    @category = Category.find(params[:id])
    @drugs = @category.drugs_ordered_by_ratings
    @total_drugs_number = @drugs.size
    @total_ratings_number = @category.ratings_number
    @filtered_ratings_number = @total_ratings_number
    @filtered_sideffects = @category.sideffects
    @total_sideffects_number = @filtered_sideffects.size
    @filter_params = {}
    @page_title = @category.name
    @is_show_category_initials = true
  end
  
  def filter_sideffects
    @category = Category.find(params[:id])
    @filtered_ratings_number = @category.ratings_number(params)
    @filtered_sideffects = @category.sideffects(params)
    @filter_params = {}
    @filter_params[:sex] = params[:sex]
    @filter_params[:age] = params[:age]
    @filter_params[:time_taken] = params[:time_taken]
    render :partial => "category_sideffects", :layout => false
  end
  
  def show_sideffect_detail
    category = Category.find(params[:category_id])
    @sideffect = Sideffect.find(params[:sideffect_id])
    @sideffect_drugs = @sideffect.drugs_by_category(category, params)
    @sideffect_ratings_number = @sideffect.ratings_number_by_category(category, params)
    render :partial => "sideffect_detail", :layout => false
  end
end
